package AdminController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;

import com.ibatis.sqlmap.client.SqlMapException;

import Ara_Bean.NboardBean;
import Ara_Bean.RboardBean;
import Ara_Dao.RboardDao;

public class BoardInsert extends AbstractCommandController{

	private RboardDao rboardDao;
	
	public void setRboardDao(RboardDao rboardDao) {
		this.rboardDao = rboardDao;
	}
	
	@Override
	protected ModelAndView handle(HttpServletRequest request,
			HttpServletResponse response, Object obj, BindException error)
			throws Exception {

		System.out.println("게시글입력실행");
		System.out.println(request.getParameter("nb_type"));
		
		NboardBean Nboardbean = (NboardBean)obj;
		
		try {
			rboardDao.NboardInsert(Nboardbean);
			System.out.println(Nboardbean);
			System.out.println(Nboardbean.getNb_type());
			System.out.println("게시글입력성공");
			
		} catch (SqlMapException e) {
			e.printStackTrace();
			System.out.println("게시글입력실패");
		}
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("redirect:/boardAdmin.admin");
		
		return mav;
	}
	
}
